package com.evan.review.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.evan.review.R;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;

/**
 * 底部弹出的DialogFragment
 * 基于Material Design的BottomSheetDialogFragment
 */
public class CustomBottomSheetDialogFragment extends BottomSheetDialogFragment {

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_bottom_sheet, container, false);
        
        Button btnOption1 = view.findViewById(R.id.btn_option1);
        Button btnOption2 = view.findViewById(R.id.btn_option2);
        Button btnOption3 = view.findViewById(R.id.btn_option3);
        Button btnCancel = view.findViewById(R.id.btn_cancel);
        
        View.OnClickListener optionClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int id = v.getId();
                String message = "选择了选项";
                
                if (id == R.id.btn_option1) {
                    message = "选择了选项1";
                } else if (id == R.id.btn_option2) {
                    message = "选择了选项2";
                } else if (id == R.id.btn_option3) {
                    message = "选择了选项3";
                }
                
                if (getActivity() instanceof DialogFragmentActivity) {
                    ((DialogFragmentActivity) getActivity()).logMessage("BottomSheet: " + message);
                } else {
                    Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show();
                }
                
                dismiss();
            }
        };
        
        btnOption1.setOnClickListener(optionClickListener);
        btnOption2.setOnClickListener(optionClickListener);
        btnOption3.setOnClickListener(optionClickListener);
        btnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (getActivity() instanceof DialogFragmentActivity) {
                    ((DialogFragmentActivity) getActivity()).logMessage("BottomSheet: 取消操作");
                }
                dismiss();
            }
        });
        
        return view;
    }
} 